package com.jinmdz.fmis.api.api.controller;

import com.jinmdz.fmis.api.api.model.area.AreaOptionItem;
import com.jinmdz.fmis.api.api.model.area.AreaParentData;
import com.jinmdz.fmis.api.api.model.common.IdData;
import com.jinmdz.fmis.api.api.service.AreaService;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.core.model.OptionItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 行政区划编码信息相关接口
 *
 * @author LiCongLu
 * @date 2020-01-16 17:25
 */
@Api(description = "行政区划编码信息相关接口")
@RestController()
@RequestMapping("/api/area")
public class AreaController extends BaseController {

    @Resource
    private AreaService areaService;

    /**
     * 加载省市县信息
     *
     * @param
     * @return
     * @author LiCongLu
     * @date 2020-01-16 17:29
     */
    @ApiOperation(value = "加载省市县信息", notes = "为殡仪馆业务洽谈功能中下拉列表提供省市县信息，格式为根据控件定制")
    @PostMapping("/load-province-city-county")
    public BaseResult<AreaOptionItem> loadProvinceCityCounty() {
        return resultHandler(userItem -> areaService.loadProvinceCityCounty());
    }

    /**
     * 根据区县ID加载乡镇、街道信息
     *
     * @param data 区县ID数据
     * @return
     * @author LiCongLu
     * @date 2020-01-19 11:02
     */
    @ApiOperation(value = "根据区县ID加载乡镇、街道信息", notes = "为殡仪馆业务洽谈功能中下拉列表提供街道信息")
    @PostMapping("/load-street-with-parent-id")
    public BaseResult<OptionItem> loadStreetWithParentId(@RequestBody IdData data) {
        return resultHandler(data, userItem -> areaService.loadAreaWithParentId(data.getId()));
    }

    /**
     * 根据乡镇街道ID加载村信息
     *
     * @param data 乡镇街道ID数据
     * @return
     * @author LiCongLu
     * @date 2020-01-19 11:04
     */
    @ApiOperation(value = "根据乡镇街道ID加载村信息", notes = "加载村信息")
    @PostMapping("/load-village-with-parent-id")
    public BaseResult<OptionItem> loadVillageWithParentId(@RequestBody IdData data) {
        return resultHandler(data, userItem -> areaService.loadAreaWithParentId(data.getId()));
    }

    /**
     * 按照主键加载子行政区划
     *
     * @param data 请求条件
     * @return
     * @author LiCongLu
     * @date 2020-05-21 17:03
     */
    @ApiOperation(value = "按照主键加载子行政区划", notes = "按照主键加载子行政区划，可设定是否加省市区县")
    @PostMapping("/load-children-with-parent-id")
    public BaseResult<OptionItem> loadChildrenWithParentId(@RequestBody AreaParentData data) {
        return resultHandler(userItem -> areaService.loadChildrenWithParentId(data));
    }
}
